/*
 * @Author: NJ_1098 xiabaoxin
 * @Date: 2025-02-13 13:54:17
 * @LastEditors: NJ_1098 xiabaoxin
 * @LastEditTime: 2025-02-14 16:15:37
 * @Description: 定时器
 */
const schedule = require("node-schedule");
const moment = require("moment");
const logger = require("../log/log.js");

class Timer {
  /**
   * @author: NJ_1098 xiabaoxin
   * @description: 每月最后一天定时器任务(Cron 表达式)
   * @return {*}
   */
  static taskForLastDayOfMonth() {
    schedule.scheduleJob("* * * L * ?", () => {
      // 清空主要日志文件
      logger.clearOrDeleteOldLogFilesByNeeds();
      // 删除错误日志文件
      logger.clearOrDeleteOldLogFilesByNeeds(
        `error.${moment().format("YYYYMM")}`,
        true
      );
    });
  }

  /**
   * @author: NJ_1098 xiabaoxin
   * @description: 每周周日晚上11:59:59定时器任务(Cron 表达式)
   * @return {*}
   */  
  static taskForEndOfWeek(){
    schedule.scheduleJob("59 59 23 * * 7", () => {
      // 清空主要日志文件
      logger.clearOrDeleteOldLogFilesByNeeds();
      // 删除错误日志文件
      logger.clearOrDeleteOldLogFilesByNeeds(
        `error.${moment().format("YYYYMM")}`,
        true
      );
    });
  }
}

module.exports = Timer;
